<?php
namespace app\sys\api;

use api\auth\Token;
use api\common\Api;

class Common extends Api
{
    protected $_error = '';
    protected $_needCheckUser = true;
    protected $_needCheckToken = true;

    protected function checkAuth()
    {
        $UID = getUid();

        if ($this->_needCheckUser && empty($UID)) {
            $this->_error = $this->error('登录超时', 401);
            return false;
        }
        if ($this->_needCheckToken) {
            if (!Token::check_token(input('server.http_token'))) {
                $this->_error = $this->error('认证失败', 401);
                return false;
            }
        }

        return true;
    }
}